package com.zenithmind.library.service;

import com.zenithmind.common.result.PageResult;
import com.zenithmind.common.result.Result;
import com.zenithmind.library.pojo.dto.FineRecordCreateDTO;
import com.zenithmind.library.pojo.dto.FineRecordUpdateDTO;
import com.zenithmind.library.pojo.query.FineRecordQuery;
import com.zenithmind.library.pojo.vo.FineRecordVO;

import java.math.BigDecimal;
import java.util.List;

/**
 * 罚金记录服务接口
 * 遵循接口隔离原则：只包含罚金记录相关的业务方法
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
public interface FineRecordService {

    /**
     * 分页查询罚金记录
     * 
     * @param query 查询条件
     * @return 分页结果
     */
    PageResult<FineRecordVO> getFineRecordPage(FineRecordQuery query);

    /**
     * 根据ID查询罚金记录详情
     * 
     * @param id 罚金记录ID
     * @return 罚金记录详情
     */
    Result<FineRecordVO> getFineRecordById(String id);

    /**
     * 根据用户ID查询罚金记录
     * 
     * @param userId 用户ID
     * @param status 状态（可选）
     * @return 罚金记录列表
     */
    Result<List<FineRecordVO>> getFineRecordsByUserId(String userId, Integer status);

    /**
     * 根据借阅记录ID查询罚金记录
     * 
     * @param borrowRecordId 借阅记录ID
     * @return 罚金记录列表
     */
    Result<List<FineRecordVO>> getFineRecordsByBorrowRecordId(String borrowRecordId);

    /**
     * 创建罚金记录
     * 
     * @param createDTO 创建参数
     * @return 创建结果
     */
    Result<FineRecordVO> createFineRecord(FineRecordCreateDTO createDTO);

    /**
     * 更新罚金记录
     * 
     * @param id 罚金记录ID
     * @param updateDTO 更新参数
     * @return 更新结果
     */
    Result<FineRecordVO> updateFineRecord(String id, FineRecordUpdateDTO updateDTO);

    /**
     * 删除罚金记录
     * 
     * @param id 罚金记录ID
     * @return 删除结果
     */
    Result<Void> deleteFineRecord(String id);

    /**
     * 批量删除罚金记录
     * 
     * @param ids 罚金记录ID列表
     * @return 删除结果
     */
    Result<Void> batchDeleteFineRecords(List<String> ids);

    /**
     * 支付罚金
     * 
     * @param id 罚金记录ID
     * @param paymentMethod 支付方式
     * @param transactionId 交易ID
     * @return 支付结果
     */
    Result<Void> payFine(String id, String paymentMethod, String transactionId);

    /**
     * 减免罚金
     * 
     * @param id 罚金记录ID
     * @param waiveAmount 减免金额
     * @param waiveReason 减免原因
     * @return 减免结果
     */
    Result<Void> waiveFine(String id, BigDecimal waiveAmount, String waiveReason);

    /**
     * 取消罚金
     * 
     * @param id 罚金记录ID
     * @param cancelReason 取消原因
     * @return 取消结果
     */
    Result<Void> cancelFine(String id, String cancelReason);

    /**
     * 计算逾期罚金
     * 
     * @param borrowRecordId 借阅记录ID
     * @param overdueDays 逾期天数
     * @return 罚金金额
     */
    Result<BigDecimal> calculateOverdueFine(String borrowRecordId, Integer overdueDays);

    /**
     * 自动生成逾期罚金记录
     * 
     * @param borrowRecordId 借阅记录ID
     * @return 生成结果
     */
    Result<FineRecordVO> generateOverdueFine(String borrowRecordId);

    /**
     * 获取用户未支付罚金总额
     * 
     * @param userId 用户ID
     * @return 未支付罚金总额
     */
    Result<BigDecimal> getUnpaidFineAmount(String userId);

    /**
     * 获取罚金统计信息
     * 
     * @param userId 用户ID（可选）
     * @return 统计信息
     */
    Result<FineStatisticsVO> getFineStatistics(String userId);

    /**
     * 导入罚金记录数据
     * 
     * @param fineRecords 罚金记录列表
     * @return 导入结果
     */
    Result<String> importFineRecords(List<FineRecordCreateDTO> fineRecords);

    /**
     * 导出罚金记录数据
     * 
     * @param query 查询条件
     * @return 导出结果
     */
    Result<String> exportFineRecords(FineRecordQuery query);

    /**
     * 罚金统计VO
     */
    class FineStatisticsVO {
        private Integer totalRecords;
        private BigDecimal totalAmount;
        private BigDecimal paidAmount;
        private BigDecimal unpaidAmount;
        private BigDecimal waivedAmount;
        private Integer paidRecords;
        private Integer unpaidRecords;
        private Integer waivedRecords;
        private Integer cancelledRecords;

        // getters and setters
        public Integer getTotalRecords() { return totalRecords; }
        public void setTotalRecords(Integer totalRecords) { this.totalRecords = totalRecords; }
        
        public BigDecimal getTotalAmount() { return totalAmount; }
        public void setTotalAmount(BigDecimal totalAmount) { this.totalAmount = totalAmount; }
        
        public BigDecimal getPaidAmount() { return paidAmount; }
        public void setPaidAmount(BigDecimal paidAmount) { this.paidAmount = paidAmount; }
        
        public BigDecimal getUnpaidAmount() { return unpaidAmount; }
        public void setUnpaidAmount(BigDecimal unpaidAmount) { this.unpaidAmount = unpaidAmount; }
        
        public BigDecimal getWaivedAmount() { return waivedAmount; }
        public void setWaivedAmount(BigDecimal waivedAmount) { this.waivedAmount = waivedAmount; }
        
        public Integer getPaidRecords() { return paidRecords; }
        public void setPaidRecords(Integer paidRecords) { this.paidRecords = paidRecords; }
        
        public Integer getUnpaidRecords() { return unpaidRecords; }
        public void setUnpaidRecords(Integer unpaidRecords) { this.unpaidRecords = unpaidRecords; }
        
        public Integer getWaivedRecords() { return waivedRecords; }
        public void setWaivedRecords(Integer waivedRecords) { this.waivedRecords = waivedRecords; }
        
        public Integer getCancelledRecords() { return cancelledRecords; }
        public void setCancelledRecords(Integer cancelledRecords) { this.cancelledRecords = cancelledRecords; }
    }
}
